/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    bool isCousins(TreeNode* root, int a, int b) {
        vector<TreeNode*>q1;
        q1.push_back(root);
        int cnt = 1;
        while (q1.size()) {
            cnt++;
            vector<TreeNode*>q2;
            unordered_map<int, int>mp;
            for (auto x : q1) {
                if (x->left && x->right) {
                    q2.push_back(x->left);
                    q2.push_back(x->right);
                    bool f = 0;
                    if (mp[a] || mp[b])f = 1;
                    mp[x->left->val] = 1;
                    mp[x->right->val] = 1;
                    if (f)continue;
                    if (mp[a] || mp[b]) {
                        cout << "chenbiaoren" << endl;
                        if (mp[a] && mp[b])return 0;
                    }
                }
                else if (x->left) {
                    q2.push_back(x->left);
                    mp[x->left->val] = 1;
                }
                else if (x->right) {
                    q2.push_back(x->right);
                    mp[x->right->val] = 1;
                }
            }
            if (mp[a] || mp[b]) {
                cout << "cnt==" << cnt << endl;
                for (auto z : mp) {
                    cout << "z==" << z.first << "   mp[z]==" << z.second << endl;
                }
                if (mp[a] && mp[b])return 1;
                return 0;
            }
            q1 = move(q2);
        }
        return 0;
    }
};